package org.jeecg.modules.demo.certificate.Utils;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.client.j2se.MatrixToImageWriter;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.text.DocumentException;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.pdfbox.io.MemoryUsageSetting;
import org.apache.pdfbox.multipdf.PDFMergerUtility;
//import org.codehaus.jettison.json.JSONObject;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.PDFTextStripperByArea;
import org.jeecg.modules.demo.certificate.service.ISchoolCertificatesService;
import org.springframework.beans.factory.annotation.Value;

import org.apache.http.*;

import java.io.*;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;

import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
@Slf4j
public class JZUtils {
    @Value("${jeecg.path.upload}")
    private String uploadPath;
    private ISchoolCertificatesService schoolCertificatesService;

//    public static String ThreeGoodStudent(String code) throws IOException, DocumentException {
//
//
//
//        /* 导入PDF模板 */
//String fileName = "JZtemplates/11.pdf";
//        /* 生成的新文件路径 */
//        String file_name = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
//        String newPDFPath = "/opt/upFiles/" + file_name + ".pdf";
//
//        try {
//            com.itextpdf.text.pdf.PdfReader reader = new com.itextpdf.text.pdf.PdfReader(fileName);
//            ByteArrayOutputStream bos = new ByteArrayOutputStream();
//
//            /* 2.读取PDF模板内容 */
//            PdfStamper ps = new PdfStamper(reader, bos);
//
//            System.out.println("采用PDF模板:" + fileName);
//
//            /* 3.法1:设置使用itext-asian.jar的中文字体 */
//////            BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
////
////			/*法2:使用项目下的自定义的中文字体
////			BaseFont bf = BaseFont.createFont("static/font/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
////
////			/*法3:使用windows系统下的字体库
////			bfChinese = BaseFont.createFont("c://windows//fonts//simsun.ttc,1",BaseFont.IDENTITY_H, false);*/
//////            BaseFont bf = BaseFont.createFont("c://windows//fonts//simsun.ttc,1", BaseFont.IDENTITY_H, false);
//////            Font font = new Font(bf, 14);
//////            ArrayList<BaseFont> fontList = new ArrayList<BaseFont>();
//////            fontList.add(bf);
//////
//////            /* 4.获取模板中的所有字段 */
//////            AcroFields fields = ps.getAcroFields();
//////            fields.setSubstitutionFonts(fontList);
//////
//////            //写入字段
//////            fields.setField("name", name);
//////            fields.setField("cert_name", cert_name);
//////            fields.setField("cert_id", cert_id);
//////            fields.setField("time", time);
//
//            //写入二维码
//            //Image image = Image.getInstance("save.png");
//            Image image = Image.getInstance(QRCodeUtil.createImage(code), null);
//            /*
//            int pageNo = fields.getFieldPositions("image").get(0).page;
//            PdfContentByte over = ps.getOverContent(1);
//            Rectangle signRect = fields.getFieldPositions("image").get(0).position;
//            float x = signRect.getLeft();
//            float y = signRect.getBottom();
//            image.scaleToFit(signRect.getWidth(),signRect.getHeight());
//            */
//            PdfContentByte over = ps.getOverContent(1);
//            image.setAbsolutePosition(600, 150);
//            over.addImage(image);
//
//
//            /* 必须要调用这个，否则文档不会生成的 */
//            ps.setFormFlattening(true);
//            ps.close();
//
//            /* 5.将要生成的目标PDF文件名称 */
//            OutputStream fos = new FileOutputStream(newPDFPath);
//            fos.write(bos.toByteArray());
//            System.out.println("新证书已生成:" + newPDFPath);
//
//
//            fos.flush();
//            fos.close();
//            bos.close();
//        } catch (IOException e) {
//            System.out.println("证书生成失败,原因:" + e.getLocalizedMessage());
//        } catch (DocumentException e) {
//            System.out.println("证书生成失败,原因:" + e.getLocalizedMessage());
//        }
//        return file_name + ".pdf";
//    }


private static void generateQRCodeImage(String text, int width, int height, String filePath) throws WriterException, IOException {
    QRCodeWriter qrCodeWriter = new QRCodeWriter();

    BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);

    Path path = FileSystems.getDefault().getPath(filePath);

    MatrixToImageWriter.writeToPath(bitMatrix, "PNG", path);

}
    public  String ThreeGoodStudent2(String name, String cert_name, String cert_id, String time, String code, String id) throws IOException, DocumentException {

        /* 导入PDF模板 */
        String fileName1 = "/font/三好学生标兵6字封面1-3.pdf";
        String fileName2 = "/font/三好学生标兵6字封面4-6.pdf";
        String fileName3 = "/font/三好学生标兵6字封面7-9.pdf";
        String fileName4 = "/font/三好学生标兵4字封面1-3.pdf";
        String fileName5 = "/font/三好学生标兵4字封面4-6.pdf";
        String fileName6 = "/font/三好学生标兵4字封面7-9.pdf";
//        String fileName1 = "E:\\school_certificates2\\jeecg-module-demo\\src\\main\\resources\\static\\font\\三好学生标兵11.21封面11.pdf";
//        String fileName2 = "E:\\school_certificates2\\jeecg-module-demo\\src\\main\\resources\\static\\font\\三好学生标兵11.21封面22.pdf";
//        String fileName3= "E:\\school_certificates2\\jeecg-module-demo\\src\\main\\resources\\static\\font\\三好学生标兵11.21封面55.pdf";
//        String fileName4 = "E:\\school_certificates2\\jeecg-module-demo\\src\\main\\resources\\static\\font\\三好学生标兵11.21封面66.pdf";
//        String fileName = "/opt/upFiles/三好学生标兵11.21封面1.pdf";
        /* 生成的新文件路径 */
        String file_name = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String newPDFPath = "/opt/upFiles/" + file_name + ".pdf";
        String newPDFPath2 = "/opt/upFiles/" + file_name + ".png";
        PdfDocument pdfDocument =null;
        try {
            if(name.length()<4){

                if(cert_name.length()>6){
                    pdfDocument = new PdfDocument(new PdfReader(fileName1), new PdfWriter(newPDFPath));
                }else {
                    pdfDocument = new PdfDocument(new PdfReader(fileName4), new PdfWriter(newPDFPath));
                }
            }else if(name.length()<7){
                if(cert_name.length()>6){
                    pdfDocument = new PdfDocument(new PdfReader(fileName2), new PdfWriter(newPDFPath));
                }else {
                    pdfDocument = new PdfDocument(new PdfReader(fileName5), new PdfWriter(newPDFPath));
                }
            }else {
                if(cert_name.length()>6){
                    pdfDocument = new PdfDocument(new PdfReader(fileName3), new PdfWriter(newPDFPath));
                }else {
                    pdfDocument = new PdfDocument(new PdfReader(fileName6), new PdfWriter(newPDFPath));
                }
            }


            PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDocument, false);//不检验是否存在
            PdfFont font = PdfFontFactory.createFont("/font/FangZhengDaBiaoSongJianTi-1.ttf");
//            PdfFont font = PdfFontFactory.createFont("/opt/upFiles/FangZhengDaBiaoSongJianTi-1.ttf");
//            FontProgram fontProgram = FontProgramFactory.createFont (this.getClass ().getResource ("src/main/resources/static/font/FangZhengDaBiaoSongJianTi-1.ttf").getFile ());
//            PdfFont font2 = PdfFontFactory.createFont ("E:\\school_certificates2\\jeecg-module-demo\\src\\main\\resources\\static\\font\\simsun.ttc,1");
            PdfFont font2 = PdfFontFactory.createFont ("/font/simsun.ttc,1");
            DeviceRgb color = new DeviceRgb(0, 0, 0);
            DeviceRgb color2 = new DeviceRgb(214, 22, 25);
            form.getFormFields().get("name").setValue(name).setColor(color).setFont(font).setFontSize(26);
            form.getFormFields().get("cert_name").setValue("“"+cert_name+"”").setColor(color2).setFont(font).setFontSize(36);
            form.getFormFields().get("cert_id").setValue(cert_id).setColor(color2).setFont(font).setFontSize(14);
//            for (Map.Entry<String, String> entry : map.entrySet()
//            ) {
//                form.getFormFields().get(entry.getKey()).setValue(entry.getValue()).setColor(color).setFont(font).setFontSize(23);
//            }

            //写入二维码
//            try {
//                generateQRCodeImage(code, 350, 350, newPDFPath2);
//            } catch (WriterException e) {
//                e.printStackTrace();
//            }
//            com.itextpdf.forms.fields.PdfFormField field=form.getField("image");
//            List<PdfWidgetAnnotation> widgets=field.getWidgets();
//            PdfWidgetAnnotation widget=widgets.get(0);
//            float x1=widget.getRectangle().getAsNumber(0).floatValue();
//            float y1=widget.getRectangle().getAsNumber(1).floatValue();
//            float x2=widget.getRectangle().getAsNumber(2).floatValue();
//            float y2=widget.getRectangle().getAsNumber(3).floatValue();
//            float fieldWidth=x2-x1;
//            float fieldHeight=y2-y1;
////            Image image = Image.getInstance(QRCodeUtil.createImage(code), null);
//            com.itextpdf.layout.element.Image image=new com.itextpdf.layout.element.Image(ImageDataFactory.create(newPDFPath2));
//
//            com.itextpdf.layout.element.Image image1= image.scaleToFit(fieldWidth,fieldHeight);
//            float scaledWidth=image.getImageScaledWidth();
//            float scaledHeight=image.getImageScaledWidth();
//            float centerX=x1+(fieldWidth/2)-(scaledWidth/2);
//            float centerY=y1+(fieldHeight/2)-(scaledHeight/2);
//            image.setFixedPosition(2,centerX,centerY);
//            Document document=new Document(pdfDocument);
//            document.add(image);
//            System.out.println("新证书已生成:" + newPDFPath);
            log.info("新证书已生成:" + newPDFPath);


//            document.close();
            form.flattenFields();
            pdfDocument.close();
            if(!name.equals(hanYou(newPDFPath))){

//                System.out.println(hanYou(hanYou(newPDFPath)));
                return ThreeGoodStudent3(name,cert_name,cert_id,time,code,id);
            }




        }catch (IOException e) {
//            System.out.println("证书生成失败,原因:" + e.getLocalizedMessage());
            log.info("证书生成失败,原因:" + e.getLocalizedMessage());
        }

        return file_name + ".pdf";
    }

    public  String ThreeGoodStudent3(String name, String cert_name, String cert_id, String time, String code, String id) throws IOException, DocumentException {

        /* 导入PDF模板 */
        String fileName1 = "/font/三好学生标兵6字封面1-3.pdf";
        String fileName2 = "/font/三好学生标兵6字封面4-6.pdf";
        String fileName3 = "/font/三好学生标兵6字封面7-9.pdf";
        String fileName4 = "/font/三好学生标兵4字封面1-3.pdf";
        String fileName5 = "/font/三好学生标兵4字封面4-6.pdf";
        String fileName6 = "/font/三好学生标兵4字封面7-9.pdf";
        /* 生成的新文件路径 */
        String file_name = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        String newPDFPath = "/opt/upFiles/" + file_name + ".pdf";
        String newPDFPath2 = "/opt/upFiles/" + file_name + ".png";
        PdfDocument pdfDocument =null;
        try {
            if(name.length()<4){

                if(cert_name.length()>6){
                    pdfDocument = new PdfDocument(new PdfReader(fileName1), new PdfWriter(newPDFPath));
                }else {
                    pdfDocument = new PdfDocument(new PdfReader(fileName4), new PdfWriter(newPDFPath));
                }
            }else if(name.length()<7){
                if(cert_name.length()>6){
                    pdfDocument = new PdfDocument(new PdfReader(fileName2), new PdfWriter(newPDFPath));
                }else {
                    pdfDocument = new PdfDocument(new PdfReader(fileName5), new PdfWriter(newPDFPath));
                }
            }else {
                if(cert_name.length()>6){
                    pdfDocument = new PdfDocument(new PdfReader(fileName3), new PdfWriter(newPDFPath));
                }else {
                    pdfDocument = new PdfDocument(new PdfReader(fileName6), new PdfWriter(newPDFPath));
                }
            }


            PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDocument, false);//不检验是否存在
            PdfFont font = PdfFontFactory.createFont("/font/FangZhengDaBiaoSongJianTi-1.ttf");

            PdfFont font2 = PdfFontFactory.createFont ("/font/simsun.ttc,1");
            DeviceRgb color = new DeviceRgb(0, 0, 0);
            DeviceRgb color2 = new DeviceRgb(214, 22, 25);
            form.getFormFields().get("name").setValue(name).setColor(color).setFont(font2).setFontSize(26);
            form.getFormFields().get("cert_name").setValue("“"+cert_name+"”").setColor(color2).setFont(font).setFontSize(36);
            form.getFormFields().get("cert_id").setValue(cert_id).setColor(color2).setFont(font).setFontSize(14);

//            System.out.println("新证书已生成:" + newPDFPath);
            log.info("新证书已生成:" + newPDFPath);
            form.flattenFields();
            pdfDocument.close();





        }catch (IOException e) {
//            System.out.println();
            log.info("证书生成失败,原因:" + e.getLocalizedMessage());
        }

        return file_name + ".pdf";
    }

    public static byte[] doGet(String uri,Map<String, String> mapParams,String token){

            // 在uri上拼接参数2.那么一个完整的url地址，基本格式如下：
            // https://host:port/path?xxx=aaa&ooo=bbb
            Set<String> keySet = mapParams.keySet();
            int i = 0;

//                if (i == 0) {
//                    uri = uri + "?" + key + "=" + mapParams.get(key);
//                } else {
//                    uri = uri + "&" + key + "=" + mapParams.get(key);
//                }
                uri =uri + "/" + mapParams.get("type")+ "/" + mapParams.get("docId");


            byte[] bytes=httpGet(uri,token);

//            // 创建一个get请求
//            HttpGet get = new HttpGet(uri);
//            get.setHeader("X-Bjca-Token",  token);
//            // 设置请求头
////            get.addHeader(Constants.HEADER_MEDIA_TYPE_NAME, Constants.HEADER_MEDIA_TYPE_VALUE);
////            get.addHeader(Constants.CONTENT_TYPE, Constants.CONTENT_TYPE_FORM);
//            // 创建一个客户端
//            HttpClient client = HttpClients.createDefault();
//            // 客户端发送请求，接受响应
//            HttpResponse response = client.execute(get);
//            FileUtils.writeByteArrayToFile(new File("路径"),response.getEntity());
            return bytes;


    }


    public static String doGet(String uri, Map<String, Object> mapParams) {
        try {
            // 在uri上拼接参数2.那么一个完整的url地址，基本格式如下：
            // https://host:port/path?xxx=aaa&ooo=bbb
            Set<String> keySet = mapParams.keySet();
            int i = 0;
            for (String key : keySet) {
                if (i == 0) {
                    uri = uri + "?" + key + "=" + mapParams.get(key);
                } else {
                    uri = uri + "&" + key + "=" + mapParams.get(key);
                }
//                uri =uri + "/" + mapParams.get(key);
                i++;
            }
            // 创建一个get请求
            HttpGet get = new HttpGet(uri);
            // 设置请求头
//            get.addHeader(Constants.HEADER_MEDIA_TYPE_NAME, Constants.HEADER_MEDIA_TYPE_VALUE);
//            get.addHeader(Constants.CONTENT_TYPE, Constants.CONTENT_TYPE_FORM);
            // 创建一个客户端
            HttpClient client = HttpClients.createDefault();
            // 客户端发送请求，接受响应
            HttpResponse response = client.execute(get);
            return getResult(response);
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 获取响应结果
     *
     * @param response
     * @return
     * @throws IOException
     */
    public static String getResult(HttpResponse response) throws IOException {
        // 获取状态码
        int code = response.getStatusLine().getStatusCode();
        System.out.println(code);
        // 获取body
        HttpEntity entity = response.getEntity();

        String body = EntityUtils.toString(entity);
        System.out.println(body);
        // 获取头信息
        Header[] allHeaders = response.getAllHeaders();
        String headers = Arrays.toString(allHeaders);
        System.out.println(headers);

        // 返回body
        return body;
    }
    /**
     * httpclient发送get请求
     */
    public static byte[] httpGet(String uri,String token) {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        byte[] fileBytes = null;
        try {
            // 创建httpclient get请求.
            HttpGet httpget = new HttpGet(uri);
            httpget.setHeader("X-Bjca-Token",  token);
            // 执行get请求.
            CloseableHttpResponse response = httpclient.execute(httpget);
            try {
                //获取响应实体
                HttpEntity entity = response.getEntity();
                InputStream inputContent = entity.getContent();
                fileBytes = input2byte(inputContent);
            } finally {
                response.close();
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            // 关闭连接,释放资源
            try {
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return fileBytes;
    }
    public static File mulFile2One(List<File> files,String targetPath) throws IOException {
        // pdf合并工具类
        PDFMergerUtility mergePdf = new PDFMergerUtility();
        for (File f : files) {
//            if(f.exists()){
            // 循环添加要合并的pdf
            mergePdf.addSource(f);
//            }
        }
        // 设置合并生成pdf文件名称
        mergePdf.setDestinationFileName(targetPath);
        // 合并pdf
        mergePdf.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
        return new File(targetPath);
    }

    /**
     * inputStream转换为byte字节数组
     * @param inStream
     * @return
     * @throws IOException
     */
    public static final byte[] input2byte(InputStream inStream) throws IOException {
        ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
        byte[] buff = new byte[100];
        int rc = 0;
        while ((rc = inStream.read(buff, 0, 100)) > 0) {
            swapStream.write(buff, 0, rc);
        }
        byte[] in2b = swapStream.toByteArray();
        return in2b;
    }




//    /**
//     * 参数为json
//     * @param url
//     * @param token
//     * @return
//     * @throws IOException
//     */
    public static String postJson(String url, String token,byte[] fileBase64Str,String docName,String endTime,String taskName) throws IOException {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(url);
        Map<String ,Object>  paramMap= new HashMap<>();
        paramMap.put("unCreditCode", "121000007246859063");
        paramMap.put("taskName", taskName);
        paramMap.put("codeStatus", "ENABLE");
        paramMap.put("autoSignSyncStatus", true);

        Map<String ,Object>  signatoryOrder= new HashMap<>();
        signatoryOrder.put("unCreditCode", "121000007246859063");
        signatoryOrder.put("orderNum", "1");
        signatoryOrder.put("signatoryType", "ORG");
        signatoryOrder.put("businessRelCode", "B001");
        signatoryOrder.put("multipleState", "DISABLE");
        List<Map<String,Object>> signatoryOrders = new ArrayList<Map<String,Object>>();
        signatoryOrders.add(signatoryOrder);
        paramMap.put("signatoryOrders", signatoryOrders);




        paramMap.put("sendReqId", "112233");
        paramMap.put("endTime", endTime);
        paramMap.put("businessType", "1624649786089066498");


        Map<String ,Object>  enterpriseSignatory= new HashMap<>();
        enterpriseSignatory.put("businessRelCode","B001");
        enterpriseSignatory.put("unCreditCode","121000007246859063");
//        List<Map<String,Object>> signatories = new ArrayList<Map<String,Object>>();
//        signatories.add(enterpriseSignatory);

        Map<String ,Object>  axis= new HashMap<>();
        axis.put("fieldX", "0.65");
        axis.put("fieldY", "0.15");
        axis.put("pageNum", "1");
        axis.put("sealType", "PartGroupSeal");
//        keyword.put("sealType", "DEPARTMENT_SEAL");
//        keyword.put("heightMoveSize","-20");
        List<Map<String,Object>> axisInfo = new ArrayList<Map<String,Object>>();
        axisInfo.add(axis);

        Map<String ,Object>  fileInfo= new HashMap<>();
        fileInfo.put("fileBase64Str", fileBase64Str);
        fileInfo.put("order", "1");
        List<Map<String,Object>> fileInfos = new ArrayList<Map<String,Object>>();
        fileInfos.add(fileInfo);

        Map<String ,Object>  exampleInfo= new HashMap<>();

        Map<String ,Object>  signatorie= new HashMap<>();
        signatorie.put("enterpriseSignatory", enterpriseSignatory);
        signatorie.put("readNoticeStatus", "DISABLE");
        signatorie.put("signType", "SIGN");
        signatorie.put("signatoryType", "ORG");
        signatorie.put("autoSignState", "ENABLE");
        signatorie.put("beforeSignExamineState", "DISABLE");
        signatorie.put("multipleState", "DISABLE");
        signatorie.put("axisInfo", axisInfo);
        List<Map<String,Object>> signatories = new ArrayList<Map<String,Object>>();
        signatories.add(signatorie);

//        exampleInfo.put("signatories", signatories);
//        exampleInfo.put("readNoticeStatus", "DISABLE");
//        exampleInfo.put("signType", "SIGN");
//        exampleInfo.put("signatoryType", "ORG");
//        exampleInfo.put("autoSignState", "ENABLE");
//        exampleInfo.put("beforeSignExamineState", "DISABLE");
//        exampleInfo.put("multipleState", "DISABLE");
        exampleInfo.put("signatories", signatories);
        exampleInfo.put("relDocId", "112233");
        exampleInfo.put("docName", docName);
        exampleInfo.put("fileInfos", fileInfos);

        List<Map<String,Object>> exampleInfos = new ArrayList<Map<String,Object>>();
        exampleInfos.add(exampleInfo);

        paramMap.put("exampleInfos", exampleInfos);
        paramMap.put("exampleUploadType", "BASE64");
        String jsonStr2 = JSONObject.toJSONString(paramMap);
        StringEntity stringEntity = new StringEntity(jsonStr2,  "utf-8");
        httpPost.setEntity(stringEntity);
        httpPost.addHeader("X-Bjca-Token", token);
        httpPost.addHeader("Content-Type", "application/json");
        CloseableHttpResponse response = null;
        try {
            response = httpclient.execute(httpPost);
            HttpEntity resultEntity = response.getEntity();
            InputStream inputStream = resultEntity.getContent();
            String content = IOUtils.toString(inputStream);
            EntityUtils.consume(resultEntity);//目的是关闭流
            return content;
        } finally {
            httpPost.releaseConnection();
            if (response != null)
                response.close();
        }
    }
    public static String hanYou(String path){
        File file = new File(path);
        String line=null;
        try (PDDocument document = PDDocument.load(file)) {

            document.getClass();

            if (!document.isEncrypted()) {
                PDFTextStripperByArea stripper = new PDFTextStripperByArea();
                stripper.setSortByPosition(true);
                PDFTextStripper tStripper = new PDFTextStripper();

                String pdfFileInText = tStripper.getText(document);

                String[] lines = pdfFileInText.split("\\r?\\n");
                line=lines[9];


            }

        } catch (InvalidPasswordException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }
        return line;
    }
//    public static void main(String[] args) throws IOException {
//        List<File> files = new ArrayList<File>();
//        files.add(new File("/font/三好学生标兵11.21封面1.pdf"));
//        files.add(new File("E:\\school_certificates2\\jeecg-module-demo\\src\\main\\resources\\static\\font\\三好学生标兵11.21封面2.pdf"));
//
//        File f = mulFile2One(files, "E:\\school_certificates2\\jeecg-module-demo\\src\\main\\resources\\static\\font\\三好学生标兵11.21封面3.pdf");
//        System.out.println(f.length());
//    }
    public static void main(String[] args) {
        File file=new File("D:\\test.pdf");

        try (PDDocument document = PDDocument.load(file)) {

            document.getClass();

            if(!document.isEncrypted()) {
                PDFTextStripperByArea stripper = new PDFTextStripperByArea();
                stripper.setSortByPosition(true);
                PDFTextStripper tStripper = new PDFTextStripper();

                String pdfFileInText = tStripper.getText(document);

                String[] lines = pdfFileInText.split("\\r?\\n");
                for(String line : lines) {
                    System.out.println(line);
                }

            }

        } catch (InvalidPasswordException e) {

            e.printStackTrace();
        } catch (IOException e) {

            e.printStackTrace();
        }

    }





//    public static void main(String[] args) throws Exception {
//        System.out.println("==========证书生成start==========");
//        JZUtils jzUtils=new JZUtils();
//        jzUtils.ThreeGoodStudent2("李祯鹏","校三好学生标兵","202203215","2022年9月15日","https://www.hbncw.cn/","12");
//
//        System.out.println("==========证书生成end============");
//    }
}
